<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2024/2/28
 * Time: 14:21
 */

namespace app\api\model;

class Order extends Base
{
    /**
     * 创建订单
     * @param $insert
     * @return int|string
     */
    static function createData($insert = []){
        return self::insert($insert);
    }

    /**
     * 单条查询
     * @param $where
     * @param $field
     * @return array|bool|\PDOStatement|string|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static function findData($where = [], $field = '*'){
        return self::where($where)->field($field)->find();
    }

    /**
     * 单条联查
     * @param $where
     * @param $field
     * @return array|bool|\PDOStatement|string|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static function findJoinData($where = [], $field = '*'){
        return self::join('up_address', 'addr_id = order_addr_id', 'LEFT')
            ->where($where)
            ->field($field)
            ->find();
    }

    /**
     * 多条查询
     * @param $where
     * @param $field
     * @param $page
     * @return bool|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static function selectData($where = [], $field = '*', $page = 1){
        return self::where($where)->field($field)->page($page, self::$limit)->order('order_time desc')->select();
    }

    /**
     * 统计数量
     * @param $where
     * @return int|string
     * @throws \think\Exception
     */
    static function countData($where = []){
        return self::where($where)->count();
    }
}